// app/api/branches/[branch]/[year]/[month]/days/route.js import { NextResponse } from "next/server"; import { listDays } from "@/lib/storage"; import { getSession } from "@/lib/auth/session"; import { canAccessBranch } from "@/lib/auth/permissions"; /** * GET /api/branches/[branch]/[year]/[month]/days */ export async function GET(request, ctx) { const session = await getSession(); if (!session) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } const { branch, year, month } = await ctx.params; console.log("[/api/branches/[branch]/[year]/[month]/days] params:", { branch, year, month, }); if (!branch || !year || !month) { return NextResponse.json( { error: "branch, year oder month fehlt" }, { status: 400 } ); } if (!canAccessBranch(session, branch)) { return NextResponse.json({ error: "Forbidden" }, { status: 403 }); } try { const days = await listDays(branch, year, month); return NextResponse.json({ branch, year, month, days }); } catch (error) { console.error("[/api/branches/[branch]/[year]/[month]/days] Error:", error); return NextResponse.json( { error: "Fehler beim Lesen der Tage: " + error.message }, { status: 500 } ); } }